<?php
require('fastcgi.php');

$client = new FCGIClient('localhost', '9000');
$content = 'key=value&w=test&fhiaf=hello';
$header = array(       
		'GATEWAY_INTERFACE' => 'FastCGI/1.0',
		'REQUEST_METHOD' => 'POST',
		'SCRIPT_FILENAME' => '/stone/google/acpp/php/http_server/test.php',
		'SERVER_SOFTWARE' => 'php/fcgiclient',
		'REMOTE_ADDR' => '127.0.0.1',
		'REMOTE_PORT' => '9985',
		'SERVER_ADDR' => '127.0.0.1',
		'SERVER_PORT' => '80',
		'SERVER_NAME' => 'mag-tured',
		'SERVER_PROTOCOL' => 'HTTP/1.1',
		'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
		'CONTENT_LENGTH' => strlen($content)
	);


$port = empty($argv[1]) ? 92 : $argv[1];
$socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_bind($socket,'127.0.0.1',$port);
socket_listen($socket);
//socket_set_nonblock($socket);

while(true)
{
    if(($newc = socket_accept($socket)) !== false)
    {
        echo "Client $newc has connected\n";
	$buf = socket_read($newc, 512);
	$buf_arr = explode("\r\n", $buf);
	print_r($buf_arr);exit;
	//$client->request($header, 
    }
}

